package com.jxdinfo.hussar.cloud.module.example.tjjc.towercrane.controller;

import com.jxdinfo.hussar.cloud.module.example.tjjc.towercrane.model.TowerCrane;
import com.jxdinfo.hussar.cloud.module.example.tjjc.towercrane.service.TowerCraneService;
import com.jxdinfo.hussar.cloud.module.example.tjjc.towercrane.vo.*;
import com.jxdinfo.hussar.platform.core.base.apiresult.ApiResponse;
import com.jxdinfo.hussar.support.audit.core.annotations.AuditLog;
import com.jxdinfo.hussar.support.audit.core.enums.AuditEventGrade;
import com.jxdinfo.hussar.support.audit.core.enums.AuditEventType;
import com.jxdinfo.hussar.support.mp.base.controller.HussarBaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 塔机表控制器
 */
@RestController(value = "tjjc.towercrane.TowerCraneController")
@AuditLog(moduleName = "塔机表")
@RequestMapping(value = "/tjjc/towerCrane")
public class TowerCraneController extends HussarBaseController<TowerCrane, TowerCraneService> {

    private static final Logger logger = LoggerFactory.getLogger(TowerCraneController.class);

    @Autowired
    private TowerCraneService towerCraneService;

    /**
     * 查询塔基列表
     * @param towerCraneSearchVO 入参
     * @return 查询结果
     */
    @AuditLog(moduleName = "塔机表", eventDesc = "查询塔基列表", eventGrade = AuditEventGrade.SERVICE_LOG_TYPE, evnetType = AuditEventType.QUERY)
    @PostMapping(path = "findByList")
    public ApiResponse<List<TowerCraneVO>> findByList(@RequestBody TowerCraneSearchVO towerCraneSearchVO){
        //todo 没有获取项目编号工具类

        return towerCraneService.findByList(towerCraneSearchVO);
    }

    /**
     * 分页查询塔机列表
     * @param towerCraneSearchVO 入参
     * @return 查询结果
     */
    @AuditLog(moduleName = "塔机表", eventDesc = "查询塔基列表", eventGrade = AuditEventGrade.SERVICE_LOG_TYPE, evnetType = AuditEventType.QUERY)
    @PostMapping(path = "findByPage")
    public ApiResponse<TowerCranePageVO> findByPage(@RequestBody TowerCraneSearchVO towerCraneSearchVO){
        //todo 没有获取项目编号工具类

        return towerCraneService.findByPage(towerCraneSearchVO);
    }

    /**
     * 获取所有塔机信息
     * @return 查询结果
     */
    @AuditLog(moduleName = "塔机表", eventDesc = "查询塔基列表", eventGrade = AuditEventGrade.SERVICE_LOG_TYPE, evnetType = AuditEventType.QUERY)
    @PostMapping(path = "findAll")
    public ApiResponse<List<TowerCraneVO>> findAll(){
        return towerCraneService.findAll();
    }

    /**
     * 根据设备类型获取塔机监测设备列表
     * @param towerCraneSearchVO 入参
     * @return 查询结果
     */
    @AuditLog(moduleName = "塔机表", eventDesc = "查询塔基列表", eventGrade = AuditEventGrade.SERVICE_LOG_TYPE, evnetType = AuditEventType.QUERY)
    @PostMapping(path = "findDeviceByProductType")
    public ApiResponse<List<DeviceInfoVO>> findDeviceByProductType(@RequestBody TowerCraneSearchVO towerCraneSearchVO){
        //todo 没有获取项目编号工具类

        return towerCraneService.findDeviceByProductType(towerCraneSearchVO);
    }

    /**
     * 根据ID获取塔机
     */
    @AuditLog(moduleName = "塔机表", eventDesc = "查询塔基", eventGrade = AuditEventGrade.SERVICE_LOG_TYPE, evnetType = AuditEventType.QUERY)
    @GetMapping("findOne")
    public ApiResponse<TowerCraneVO> findOne(@RequestParam String id) {
        //todo 没有获取项目编号工具类

        return towerCraneService.findOne(id);
    }

    /**
     * 获取塔机今日工作情况实时数据
     */
    @AuditLog(moduleName = "塔机表", eventDesc = "查询塔基", eventGrade = AuditEventGrade.SERVICE_LOG_TYPE, evnetType = AuditEventType.QUERY)
    @GetMapping("findMobileTowerRealData")
    public ApiResponse<AppTowerTodayRealDataVO> findMobileTowerRealData(@RequestParam String towerId) {
        //todo 没有获取项目编号工具类
        String tyProjectCode = "";

        return towerCraneService.findMobileTowerRealData(towerId,tyProjectCode);
    }

    /**
     * 根据项目编号和塔机Id获取塔机今日工作情况
     */
    @AuditLog(moduleName = "塔机表", eventDesc = "查询塔基", eventGrade = AuditEventGrade.SERVICE_LOG_TYPE, evnetType = AuditEventType.QUERY)
    @PostMapping("findTodayWorkSituation")
    public ApiResponse<TowerCraneVO> findTodayWorkSituation(@RequestBody TowerCraneSearchVO towerCraneSearchVO) {
        if (towerCraneSearchVO == null){
            return null;
        }
        //todo 没有获取项目编号工具类

        return towerCraneService.findTodayWorkSituation(towerCraneSearchVO);
    }

    /**
     * 获取所有设备的告警情况
     * @param towerCraneSearchVO 入参
     * @return 查询结果
     */
    @AuditLog(moduleName = "塔机表", eventDesc = "查询塔基列表", eventGrade = AuditEventGrade.SERVICE_LOG_TYPE, evnetType = AuditEventType.QUERY)
    @PostMapping(path = "findTowerAlarmCount")
    public ApiResponse<Map<String, Integer>> findTowerAlarmCount(@RequestBody TowerCraneSearchVO towerCraneSearchVO){
        if (towerCraneSearchVO == null){
            return null;
        }
        //todo 没有获取项目编号工具类

        return towerCraneService.findTowerAlarmCount(towerCraneSearchVO);
    }

    /**
     * 获取塔机今日工作情况实时数据
     */
    @AuditLog(moduleName = "塔机表", eventDesc = "查询塔基", eventGrade = AuditEventGrade.SERVICE_LOG_TYPE, evnetType = AuditEventType.QUERY)
    @GetMapping("findTowerRealData")
    public ApiResponse<TowerTodayRealDataVO> findTowerRealData(@RequestParam String id) {
        //todo 没有获取项目编号工具类
        String tyProjectCode = "";

        return towerCraneService.findTowerRealData(id, tyProjectCode);
    }

    /**
     * 新增塔机
     */
    @AuditLog(moduleName = "塔机表", eventDesc = "新增塔机", eventGrade = AuditEventGrade.SERVICE_LOG_TYPE, evnetType = AuditEventType.INSERT)
    @PostMapping("add")
    public ApiResponse<String> add(@RequestBody TowerCraneVO towerCraneVO) {
        //todo 没有获取项目编号工具类

        return towerCraneService.add(towerCraneVO);
    }

    /**
     * 修改塔机
     */
    @AuditLog(moduleName = "塔机表", eventDesc = "修改塔机", eventGrade = AuditEventGrade.SERVICE_LOG_TYPE, evnetType = AuditEventType.UPDATE)
    @PostMapping("update")
    public ApiResponse<String> update(@RequestBody TowerCraneVO towerCraneVO) {
        //todo 没有获取项目编号工具类

        return towerCraneService.updateTowerCrane(towerCraneVO);
    }

    /**
     * 修改通知配置
     */
    @AuditLog(moduleName = "塔机表", eventDesc = "修改通知配置", eventGrade = AuditEventGrade.SERVICE_LOG_TYPE, evnetType = AuditEventType.UPDATE)
    @PostMapping("updateNotice")
    public ApiResponse<String> updateNotice(@RequestBody TowerCraneVO towerCraneVO) {
        //todo 没有获取项目编号工具类

        return towerCraneService.updateNotice(towerCraneVO);
    }

    /**
     * 根据id删除塔机
     */
    @AuditLog(moduleName = "塔机表", eventDesc = "删除塔机", eventGrade = AuditEventGrade.SERVICE_LOG_TYPE, evnetType = AuditEventType.UPDATE)
    @PostMapping("deleteById")
    public ApiResponse<String> deleteById(@RequestBody TowerCraneVO towerCraneVO) {
        //todo 没有获取项目编号工具类

        return towerCraneService.deleteById(towerCraneVO);
    }
}
